package com.feng.modules.core.dao.support;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.jdbc.core.JdbcTemplate;

import com.feng.modules.core.dao.IDaoAware;

public class DaoAwareProcessor
  implements BeanPostProcessor
{
//  private LobHandler lobHandler;
  private JdbcTemplate jdbcTemplate;
  private SqlSessionTemplate sqlSessionTemplate;
//  private HibernateTemplate hibernateTemplate;

//  public void setLobHandler(LobHandler lobHandler)
//  {
//    this.lobHandler = lobHandler;
//  }
  public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
    this.jdbcTemplate = jdbcTemplate;
  }

  public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
    this.sqlSessionTemplate = sqlSessionTemplate;
  }
//  public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
//    this.hibernateTemplate = hibernateTemplate;
//  }

  public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    if ((bean instanceof IDaoAware)) {
      IDaoAware aware = (IDaoAware)bean;
//      if (this.lobHandler != null) {
//        aware.setLobHandler(this.lobHandler);
//      }
      if (this.jdbcTemplate != null) {
        aware.setJdbcTemplate(this.jdbcTemplate);
      }
      if (this.sqlSessionTemplate != null) {
        aware.setSqlSessionTemplate(this.sqlSessionTemplate);
      }
//      if (this.hibernateTemplate != null) {
//        aware.setHibernateTemplate(this.hibernateTemplate);
//      }
    }
    return bean;
  }

  public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException
  {
    return bean;
  }
}